<template>
  <view>
    <!-- #ifdef H5 -->
    <form>
      <view class="">
        <input type="text" placeholder="用户名" v-model="username" />
      </view>
      <view class="">
        <input type="text" password placeholder="密码" v-model="password" />
      </view>
      <button type="default" @click="handleLogin">登录</button>
    </form>
    <!-- #endif -->
    <!-- #ifdef MP -->
    <button type="default" @click="getUserProfile">获取用户基本信息</button>
    <!-- #endif -->
  </view>
</template>

<script>
  
  export default {
    data() {
      return {
        username: '',
        password: '',
      }
    },
    methods: {
      // #ifdef H5
      handleLogin() {
        setTimeout(() => {
          console.log('用户名：', this.username, ', 密码：', this.password, '，模拟登录成功')
          const user = {
            userInfo: {
              nickName: '小明',
              username: this.username,
              avatarUrl: 'http://www.test.com/1.jpg'
            },
            token: 'lkjasdklfjojkljaklsdfjojn'
          }
          this.$store.commit('login_success', user)
          // uni.navigateTo({
          //   url: '../mine/mine'
          // })
          uni.switchTab({
            url: '../mine/mine'
          })
        }, 2000)
      },
      // #endif
      // #ifdef MP
      getUserProfile() {
        uni.getUserProfile({
          desc: '描述',
          success(res) {
            console.log('结果：', res)
          },
          fail(err) {
            console.log('异常：', err)
          }
        })
      },
      // #endif
    }
  }
</script>

<style>

</style>
